package com.hyz.order.service.impl;

import com.hyz.common.pojo.Order;
import com.hyz.order.mapper.OrderMapper;
import com.hyz.order.service.OrderService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

@Service
public class OrderServiceImpl implements OrderService {

    @Autowired
    OrderMapper orderMapper;
    /**
     * 根据主键用户名查询订单列表
     *
     * @param username 登录用户名
     * @return
     */
    @Override
    public List<Order> findOrderByUserId(String username) {
        if (StringUtils.isEmpty(username)) {
            throw new RuntimeException("参数不能为空");
        }
        if ("lisi".equals(username)) {
            throw new RuntimeException("测试");
        }
        //创建查询条件对象
        Example example = new Example(Order.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("username",username);
        List<Order> orders = orderMapper.selectByExample(example);
        return orders;
    }
}
